package IOperation;

import book.BookList;

import java.util.Scanner;

public class BorrowOperation implements Operation{
    public  void work(BookList bookList){
        System.out.println("借阅图书");

        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入你要借阅的书名：");
        String name = scanner.nextLine();

        int choice = bookList.getUsedSize();
        for (int i = 0; i < choice; i++) {
            if (bookList.getBook(i).getName().equals(name)) {
                if(bookList.getBook(i).isBorrowed()){
                    System.out.println("这本书已借出");
                    return;
                }

                bookList.getBook(i).setBorrowed(true);
                System.out.println(bookList.getBook(i));
                System.out.println("借阅成功！");
                return;
            }
        }
        System.out.println("书架没有这本书！请重新选择");
    }
}
